package com.touchfish.material.controller;

import com.touchfish.material.common.BaseResult;
import com.touchfish.material.domain.TGoodsMaterial;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 测试
 *
 * @author touchfish
 * @date 2023/2/16
 */
@RestController
public class TestController {
    /**
     * 测试controller
     *
     * @return BaseResult
     * @author touchfish
     * @date 2023/2/16
     */
//    @GetMapping("test")
//    BaseResult test() {
//        int i=2/0;
//        System.out.println(i);
//        return BaseResult.success(new TGoodsMaterial()
//                .setMaterialName("测试")
//
//                .setMaterialCode("TEST"));
//
//    }

    /**
     * 测试controller
     *
     * @return BaseResult
     * @author touchfish
     * @date 2023/2/16
     */
    @GetMapping("testList")
    BaseResult testGetList() {
        // 新建一个list用于存放TGoodsMaterial 对象
        List<TGoodsMaterial> collect = new ArrayList<>();
        // 循环10次
        for (int i = 0; i < 10; i++) {
            // 创建新对象
            TGoodsMaterial tGoodsMaterial = new TGoodsMaterial();
            // 设置对象的属性
            tGoodsMaterial.setMaterialCode(String.valueOf(i));
            tGoodsMaterial.setMaterialName(String.valueOf(i));
            // 添加到集合
            collect.add(tGoodsMaterial);
        }
//        List<TGoodsMaterial> collect = IntStream.range(0, 10)
//                .mapToObj(x -> new TGoodsMaterial()
//                        .setMaterialName(String.valueOf(x))
//                        .setMaterialCode(String.valueOf(x)))
//                .collect(Collectors.toList());
        // 构建返回值
        return BaseResult.success(collect, 10);
    }
}
